package com.itheima.controller;

import com.itheima.domain.Users;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;

    @RequestMapping("/doRegister")
    public String doRegister(Users user) {
        userService.doRegister(user);
        return "register_success";
    }
    @RequestMapping("/doLogin")
    public ModelAndView doLogin(Users user) {
        ModelAndView mv = new ModelAndView();
        Users user1 = userService.findUser(user);
        if (user1!=null) {
            mv.addObject("user",user1);
            mv.setViewName("success");
        } else {
            mv.setViewName("failer");
        }

         return mv;


    }
}
